MainingPanel = Ext.extend(Ext.TabPanel, {
	initComponent : function() {
		MainingPanel.superclass.initComponent.call(this);
	},
	openTab : function(id,text){
		var n = this.getComponent(id);
		if (n) {
			this.setActiveTab(n);
		}else{
			var c = {
					'id' : id,
					'title' : text,
					closable : true
				};
			var pn = this.findPanel(id);
			if(!pn){
			pn = Ext.apply(c, {
					layout : 'border',
					autoScroll : true,
					items : [os.listPanel(),os.gridPanel(),os.shopsForm()]
				});
			}
			n = this.add(pn);
			this.setActiveTab(n);
		}
		
	},
	loadTab : function(node) {
		var n = this.getComponent(node.id);
		if (n) {
			this.setActiveTab(n);
		} else {
			var c = {
				'id' : node.id,
				'title' : node.text,
				closable : true
			};
			
			
			var pn = this.findPanel(node.id);
			if(node.id == "manageSL"){
				  if(!pn){
					     pn = Ext.apply(c, {
							layout : 'border',
							items : [listSL.listGrid(),listSL.grid()]
						});
					  }
					n = this.add(pn);
					listStore.load({params : {start : 0, limit : 5}});
					
		    }else if(node.id == "clientManager"){
				cstore.load({params : {start : 0, limit : 15}});
				if(!pn){
					pn = Ext.apply(c, {
					layout : 'border',
					autoScroll : true,
					items : [renders.grid()]
				});
			}
			n = this.add(pn);
			
			}else if(node.id == "bvApply"){
				bvListStore.load({params : {start : 0, limit : 5}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [bvs.listGrid(),bvs.grid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "shopping"){
				listStore.load({params : {start : 0, limit : 5}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [listSL.listGrid(),listSL.grid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "bvApply"){
				bvListStore.load({params : {start : 0, limit : 5}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [bvs.listPanel(),bvs.bvsForm(),bvs.grid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "createOrder"){
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [invoices.listPanel(),invoices.invoicesForm(),invoices.grid()]
					});
				}
				n = this.add(pn);
				invoiceListStore.load({params : {start : 0, limit : 6}});
			}else if(node.id == "createShopping"){
				
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [cs.listPanel(),cs.grid(),cs.shopsForm()]
					});
				}
				n = this.add(pn);
				csListStore.load({params : {start : 0, limit : 6}});
			}else if(node.id == "warehousing"){
				depotStore.load({params : {start : 0, limit : 6}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [depots.listPanel(),depots.gridPanel(),depots.goodsForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "storage"){
				storageStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [storages.storageGrid(),storages.storageForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "picking"){
				pickListStore.load({params : {start : 0, limit : 6}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [picks.listPanel(),picks.grid(),picks.picksForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "sale"){
				saleListStore.load({params : {start : 0, limit : 6}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [sales.listPanel(),sales.grid(),sales.salesForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "transfer"){
				transferListStore.load({params : {start : 0, limit : 6}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [transfers.listPanel(),transfers.grid(),transfers.transfersForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "inventory"){
				inventoryListStore.load({params : {start : 0, limit : 6}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						autoScroll : true,
						items : [inventorys.listPanel(),inventorys.grid(),inventorys.inventorysForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "oSell"){
				osellListStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [osellLists.osellListGrid(),osellLists.osellListForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "oFee"){
				ofeeListStore.load({params : {start : 0, limit : 5}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [ofees.feeGrid(),ofees.feeListGrid(),ofees.feeForm()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "oTax"){
				overseaTaxListStore.load({params : {start : 0, limit : 5}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [overseaTaxs.overseaTaxForm(),overseaTaxs.overseaTaxListGrid(),overseaTaxs.overseaTaxGrid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "oRecei"){
				oreceiStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [oreceis.oreceiForm(),oreceis.oreceiGrid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "oSpay"){
				osPayStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [osPays.osPayForm(),osPays.osPayGrid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "recei"){
				receivableStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [receivables.receivableGrid()]
					});
				}
				n = this.add(pn);
			}else if(node.id == "shouldPay"){
				shouldPayStore.load({params : {start : 0, limit : 15}});
				if(!pn){
				pn = Ext.apply(c, {
						layout : 'border',
						items : [shouldPays.shouldPayGrid()]
					});
				}
				n = this.add(pn);
			}else{
				n = this.add(pn ? new pn(c) : Ext.apply(c, {
					html : '你还没有实现该页面！'
				}))
			}
		//限制tab的数量
			if(this.items.getCount()>2){
				this.remove(this.items.get(1)) ;
			}
			n.show().doLayout();
		}
	
	},
	findPanel : function(name) {
		var ret;
			
			var pn = (this.ns ? this.ns : 'MainingPanel') + "."
					+ Ext.util.Format.capitalize(name) + 'Panel';
			
			var ret = eval(pn);
		return ret;
	}
});
